package com.zzl.mine.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @description 获取cookie
 * @author kevin
 * @date 2018年7月20日 上午11:39:27
 */

public class UserCookiesUtils {
	
	public static String getUserId(){
		String userId = null;
		
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		Cookie[] cookies = request.getCookies();
		if(cookies != null && cookies.length > 0){
			 for (Cookie cookie : cookies) {
				 if (cookie.getName().equals("hmtyuserid")) {
					 userId = cookie.getValue();
					 break;
				 }
			 }
		}
		return userId;
	}
	/**
	 * @Description 获取场馆id
	 * @author houjie
	 * @return
	 */
	public static String getSzsmkVenueId(){
		String szsmkVenueId = null;
		
		HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
		Cookie[] cookies = request.getCookies();
		if(cookies != null && cookies.length > 0){
			 for (Cookie cookie : cookies) {
				 if (cookie.getName().equals("szsmk_venue_id")) {
					 szsmkVenueId = cookie.getValue();
					 break;
				 }
			 }
		}
		return szsmkVenueId;
	}
}
